from tests.pytests.helpers.codegen_helpers import compile_chunk, assert_code_contains


def test_simple_arith_and_if():
    def calc(a: int, b: int) -> int:
        c = a + b - 1
        if c > 10 and a != b:
            c = c * 2
        return c

    block = compile_chunk(calc)
    assert_code_contains(
        block,
        """
        int calc(int a, int b) {
            int c = a + b - 1;
            if (c > 10 && a != b) {
                c = c * 2;
            }
            return c;
        }
        """,
    )


def test_unary_and_bool_ops():
    def g(a: int, b: int, flag: bool) -> int:
        if not flag and a < b:
            return a
        return b

    block = compile_chunk(g)
    assert_code_contains(
        block,
        """
        int g(int a, int b, bool flag) {
            if (!flag && a < b) {
                return a;
            }
            return b;
        }
        """,
    )
